import { Navigate, useRoutes } from "react-router-dom";
import UserIndex from '@/view/user/index'
import Login from '@/view/Login'
import RegisterPage from '@/view/user/registerPage'
import UserInfo from '@/view/user/UserInfo/index'

// * 导入所有router
export const routerArray= [];
const metaRouters = require.context('./modules',false,/\.tsx$/);
metaRouters.keys().forEach((item) => {
    Object.keys(metaRouters(item)).forEach((key)=>{
        routerArray.push(...metaRouters(item)[key])
    })
})
routerArray.sort((a,b)=>a.index - b.index)

export const rootRouter =[
    {
        path: "/",
        element: <Login />
    },
    {
        path: "/login",
        element: <Login />,
        meta: {
            requiresAuth: false,
            title: "登录页",
            key: "login"
        }
    },
   // {
   //      element: <UserIndex />,
   //      meta: {
   //          title: "用户组件",
   //          key:'/userIndex'
   //      },
   //      children:[
   //          {
   //              path: "/registerPage",
   //              element:<RegisterPage/>,
   //              meta: {
   //                  requiresAuth: false,
   //                  title: "注册",
   //                  key: "/registerPage"
   //              },
   //          },
   //          {
   //              path: "/userInfo",
   //              element:<UserInfo/>,
   //              meta: {
   //                  requiresAuth: false,
   //                  title: "个人信息",
   //                  key: "/userInfo"
   //              },
   //          },
   //      ],
   //  },
    ...routerArray,
   {
       path: "*",
       element: <Navigate to="/404" />
   }
]


const RouterData = () => {
    const routes = useRoutes(rootRouter);
    return routes;
};
export default RouterData;

